package com.cqc.aiyagril2.base;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.cqc.aiyagril2.R;
import com.cqc.aiyagril2.utils.ToastUtil;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.reactivex.disposables.CompositeDisposable;

/**
 * Created by ${cqc} on 2018/1/12.
 * base
 */

public abstract class BaseActivity extends AppCompatActivity {

    private Unbinder unbinder;
    protected Context context;
    protected CompositeDisposable disposable;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getLayoutResId() != 0) {
            setContentView(getLayoutResId());
            unbinder = ButterKnife.bind(this);
            disposable = new CompositeDisposable();
            context = this;
            initView(savedInstanceState);
            initData();
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (unbinder != null) {
            unbinder.unbind();
        }
    }

    public abstract int getLayoutResId();

    protected abstract void initView(Bundle savedInstanceState);

    protected abstract void initData();

    protected void showToast(String content){
        ToastUtil.showShortToast(this,content);
    }

    protected void toNextActivitySlide(Intent intent){
        startActivity(intent);
        overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left);
    }

}
